# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Paul Moore <p.f.moore@gmail.com>

_realname=sed
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.2.2
pkgrel=2
pkgdesc="Sed is a stream editor (mingw-w64)"
arch=('any')
url='https://www.gnu.org/software/sed/'
license=('GPL3')
options=('strip' '!libtool' 'staticlibs')
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        msvc_invalid_parameter_handler.patch)
sha256sums=('fea0a94d4b605894f3e2d5572e3f96e4413bcad3a085aae7367c2cf07908b2ff'
            '91967a919c8682d817730ccd242c493d0006b36dd5adc142dde3c3096e84ceeb')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p0 -i ${srcdir}/msvc_invalid_parameter_handler.patch
}

build() {
  cd $srcdir/${_realname}-${pkgver}
  ./configure --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make install DESTDIR="${pkgdir}"

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README"                 "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING"                "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
